<%
# this partial expects:
# +project+ - the current project
# +issue+ - the current issue
#
issue ||= Issue.new
path = nil
if issue.new_record?
  path = issues_path( project.name )
  back = project_path( project.name )
else
  path = issue_path( project.name, issue.local_id )
end
-%>

<% form_for issue, :url => path, :html => { :multipart => true } do |f| %>
  <%= f.error_messages %>

  <dl>
    <dt><%= f.label :summary, 'Summary', :class => 'required' %></dt>
    <dd><%= f.text_field :summary %></dd>
    <dt><%= f.label :details %></dt>
    <dd><%= f.text_area :details %></dd>
    <dt><%= label :issue, :status %></dt>
    <dd>
      <%= text_field :issue, :status, :value =>
                    ( issue.status ? issue.status.name : '' ) %>
      <div id="status_choices" class="autocomplete"></div>
      <%= auto_complete_field 'issue_status',
            :url => autocomplete_status_url,
            :update => 'status_choices',
            :param_name => 'match' %>
    </dd>
    <dt><%= label :issue, :priority %></dt>
    <dd>
      <%= text_field :issue, :priority, :value =>
                    ( issue.priority ? issue.priority.name : '' ) %>
      <div id="priority_choices" class="autocomplete"></div>
      <%= auto_complete_field 'issue_priority',
            :url => autocomplete_priority_url,
            :update => 'priority_choices',
            :param_name => 'match' %>
    </dd>
    <dt><%= label :issue, :tag_list, 'Tags' %></dt>
    <dd><%= text_field :issue, :tag_list, :value => issue.tag_list.to_s %></dd>
  </dl>
  
  <%= render :partial => 'shared/edit_attachments', :locals => { :attachments => issue.attachments } %>

    <% if issue.new_record? -%>
      <%= f.submit "Submit Issue", :class => 'submit' %>
      <small><%= link_to 'Cancel', back %></small>
    <% else -%>
      <%= f.submit "Submit Updates", :class => 'submit' %>
      <small><%= link_to 'Cancel', path %></small>
    <% end -%>
<% end %>
